<?php

class Core_Data_Generator_DefinitionInterpreter_Record {

    private $xmlRecord;

    function __construct ( $xmlRecord ) {
        $this->xmlRecord = $xmlRecord;
    }

    /**
     * Gets the name of the record.
     *
     * This is a required attribute for a 'record' element in the XML file.
     *
     * @return string
     * @exception Missing attribute 'name' in a 'record' element. <i>Exception code 108</i>.
     */
    public function getName () {
        if ( isset( $this->xmlRecord->attributes()->name ) ) {
           return (string) $this->xmlRecord->attributes()->name;
        } else {
           throw new Exception( "Missing attribute 'name' in a 'record' element.", 108 );
        }
    }

    /**
     * Gets the name of the record class.
     *
     * @return boolean|string The name of the class as string if set, <kbd>false</kbd> if not.
     */
    public function getClassName () {
        if ( isset( $this->xmlRecord->attributes()->classname ) ) {
            return (string) $this->xmlRecord->attributes()->classname;
        } else {
            return false;
        }
    }

    /**
     * Gets the filename for the record class.
     *
     * @return boolean|string The filename of the class as string if set, <kbd>false</kbd> if not.
     */
    public function getClassFilename () {
        if ( isset( $this->xmlRecord->attributes()->classfilename ) ) {
            return (string) $this->xmlRecord->attributes()->classfilename;
        } else {
            return false;
        }
    }

    /**
     * Gets the package name for the class.
     *
     * This is used by PHPDoc.
     *
     * @return boolean|string The package name for the class as string if set, <kbd>false</kbd> if not.
     */
    public function getPackageName () {
        if ( isset( $this->xmlRecord->attributes()->packagename ) ) {
            return (string) $this->xmlRecord->attributes()->packagename;
        } else {
            return false;
        }
    }

    /**
     * Gets the subpackage name for the class.
     *
     * This is used by PHPDoc.
     *
     * @return boolean|string The subpackage name for the class as string if set, <kbd>false</kbd> if not.
     */
    public function getSubpackageName () {
        if ( isset( $this->xmlRecord->attributes()->subpackagename ) ) {
            return (string) $this->xmlRecord->attributes()->subpackagename;
        } else {
            return false;
        }
    }

    public function getTable () {
        $arrXPathResult = $this->xmlRecord->xpath( ".." );
        return new Core_Data_Generator_XMLInterpreter_Table( $arrXPathResult[0] );
    }
}

?>